package com.yty.newconsult.common;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;


@Component
public class ChannelManager {
    private  static ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<String, Channel>();
    public  static void addChannel(String id, Channel channel) {
        channelMap.put(id, channel);
    }
    public  static void removeById(String id) {
        channelMap.remove(id);
    }
    public  static void removeByChannel(Channel channel) {
        channelMap.entrySet().removeIf(entry -> entry.getValue().equals(channel));
    }
    public static Channel getChannel(String id) {
        return channelMap.get(id);
    }
}
